<template>
    <div class="playsong">
        <!-- 歌单详情 -->
        <van-nav-bar title="歌单详情" left-text="返回" left-arrow @click-left="onClickLeft">
        </van-nav-bar>
        <!--歌单的顶部-->
        <div class="header">
            <img :src="coverUrl" alt="">
            <h3>{{ song.name }}</h3>
            <div class="nick">
                <img :src="song.headurl" alt="">
                <span>{{ song.description }}</span>
            </div>
            <span>播放量:{{ song.artists | numFilter(1) }}万</span>
        </div>
        <!--歌曲列表-->
        <div class="list">
            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
                <div v-for="(item, index) in list" :key="index">
                    <h4>{{ item.brand }}</h4>
                    <div class="singer">
                        <span v-for="(singerItem, index) in item.singer" :key="index">
                            {{ singerItem.name }}
                            <span v-show="index != item.singer.length - 1">/</span>
                        </span>
                        <span v-show="item.listenerCount">
                            <span>·</span>
                            <span>{{ item.listenerCount }}</span>
                        </span>
                    </div>
                </div>
            </van-list>
        </div>
    </div>
</template>     
<script>
export default {
    data() {
        return {
            song: {
                coverUrl: "",
                name: "",
                description: "",
                songs: {
                    artists: [],
                },
                brand: "",
                listenerCount: "",
                categoryName: "",
                artists: [],
            },
        };
    },
    created() {
        this.getListData()
    },
    methods: {
        getListData() {
            this.$request('get', '/top/playlist/highquality', {
                id: this.$route.params.id
            }).then(res => {
                console.log(res);
                this.songlist = res.program.songs;
                this.song.coverUrl = res.program.coverUrl
                this.song.name = res.program.name;
                this.song.description = res.program.description;
                this.song.songs = res.program.songs;
                this.song.brand = res.program.brand;
                this.song.listenerCount = res.program.listenerCount;
                this.song.categoryName = res.program.categoryName;
                this.song.artists = res.program.songs.artists;
                this.song.songs.artists = res.program.songs.artists;
            });
        },
        onClickLeft() {
            window.history.length > 1 ? this.$router.go(-1) : this.$router.push('/')
        },
        onLoad() {
            setTimeout(() => {
                this.list = this.list.concat(this.songlist.splice(0, 10))

                // 加载状态结束
                this.loading = false;

                // 数据全部加载完成
                if (this.list.length >= this.songnum) {
                    this.finished = true;
                }
            }, 1000);
        },
    },
}


</script>
<style scoped>
.header>img {
    border-radius: 1rem;
    widows: 50%;
}

.nick {
    overflow: hidden;
    display: flex;
    /**弹性布局 */
    justify-content: center;
    /**弹性布局中的内容水平居中 */
    align-items: center;
    /**弹性布局中的内容垂直居中 */
    margin-bottom: 1rem;
}

.nick>img {
    height: 2rem;
    border-radius: 50%;
    margin-right: 0.5rem;

}

.nick>span {
    height: 2rem;
    font-size: 0.8rem;
    line-height: 2rem;
}

/* 列表的样式 */
.list h4 {
    text-align: left;
    font-size: 1rem;
}

.singer {
    text-align: left;
    ;
}

.list {
    margin: 1rem
}

.singer span {
    font-size: rgb(160, 160, 190);
    font-size: 0.8rem;
}

.singer>span:nth-last-child(1)>span:nth-child(1) {
    color: red;
    font-weight: 900;
    padding: 0 0.5rem
}
</style>